Copyright (C) 2014 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Image saved on Monday May 19, 2014 at 9:55:33 PM
  Release 9.2     || Microcode 15.1 || Runtime 15.7 || Win32 1.8 || SF 4.41
  LIAR/i386 4.118 || Edwin 3.116
;You are in an interaction window of the Edwin editor.
;Type `C-h' for help, or `C-h t' for a tutorial.
;`C-h m' will describe some commands.
;`C-h' means: hold down the Ctrl key and type `h'.
;Package: (user)

(define (show x)
  (display x)
  (newline)
  x)
;Value: show

(define x (stream-map show (stream-enumerate-interval 0 10)))
;Unbound variable: stream-enumerate-interval
;To continue, call RESTART with an option number:
; (RESTART 3) => Specify a value to use instead of stream-enumerate-interval.
; (RESTART 2) => Define stream-enumerate-interval to a given value.
; (RESTART 1) => Return to read-eval-print level 1.
;Start debugger? (y or n): n

(define (stream-enum low high)
  (if (> low high)
      '()
      (cons-stream
       low 
       (stream-enum (+ 1 low) high))))
;Value: stream-enum

(define x (stream-map show (stream-enum 0 10)))
0
;Value: x

(define sum 0)
;Value: sum

(define (accum x)
  (set! sum (+ x sum))
  sum)
;Value: accum

(define seq (stream-map accum (stream-enum 1 20)))
;Value: seq

(define y (stream-filter even? seq))
;Value: y

(define z (stream-filter (lambda (x) (= (remainder x 5) 0))
			 seq))
;Value: z

(stream-ref y 7)
;Value: 136

sum
;Value: 136

(display-stream y)
;Unbound variable: display-stream
;To continue, call RESTART with an option number:
; (RESTART 4) => Specify a value to use instead of display-stream.
; (RESTART 3) => Define display-stream to a given value.
; (RESTART 2) => Return to read-eval-print level 2.
; (RESTART 1) => Return to read-eval-print level 1.
;Start debugger? (y or n): n

(define (display-stream s)
  (stream-for-each (lambda (x) (begin
				 (newline)
				 (display x)))
		   s))
;Value: display-stream

(display-stream y)

6
10
28
36
66
78
120
136
190
210
;Unspecified return value


(define ones (cons-stream 1 ones))
;Value: ones

(stream-ref ones 7)
;Value: 1

(define (add-stream x y)
  (stream-map + x y))
;Value: add-stream

(define integers (cons-stream 1 (add-stream ones integers)))
;Value: integers

(stream-ref integers 7)
;Value: 8

(stream-ref integers 1)
;Value: 2

(stream-ref integers 0)
;Value: 1

(define (mul-stream x y)
  (stream-map * x y))
;Value: mul-stream

(define factorials (cons-stream 1 (mul-stream (stream-cdr integers) factorials)))
;Value: factorials

(stream-ref factorials 0)
;Value: 1

(stream-ref factorials 1)
;Value: 2

(define (partial-sums S)
  (define y (cons-stream (stream-car S) (add-stream y (stream-cdr S)))))
;Value: partial-sums

